<!doctype html>
<html>

	<head>
		<meta charset="utf-8">
		<title></title>
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<link href="css/mui.css" rel="stylesheet" />
		<script src="js/vue.js" type="text/javascript" charset="utf-8"></script>
	</head>

	<body>
	
		<div class="mui-content" style="margin: 0 auto;">
			<div class="" style="text-align: left; font-size: large;margin-top: 50px;">
				<ul class="mui-table-view" id="user" style="background-color: rgb(239, 239, 244);">
						<li class="mui-table-view-cell">
							账号:{{user.username}}
						</li>
						<li class="mui-table-view-cell">
							金额:{{user.money}}
						</li>
						<li class="mui-table-view-cell">
							等级:{{user.lev}}
						</li>
						<li class="mui-table-view-cell">
							辅助码数量:{{user.limitcode}}
						</li>
						<li class="mui-table-view-cell">
							ID:{{user.id}}
						</li>
						
					</ul>
					<button type="button" id="backlogin" class="mui-btn mui-btn-blue">退出登录</button>
			</div>
			
			
		</div>
		<script src="js/mui.js"></script>
		<script type="text/javascript">
			(function($, doc) {
				var vm=new Vue({
				  el: '#user',
				  data: {
				    user: {}
				  }
				})
				// vm.users=[
				//       { name: '1' },
				//       { name: '2' },
				// 	  { name: '4' },
				//       { name: '3' }
				//     ]
				$.init({
					statusBarBackground: '#f7f7f7'
				 
				});
				$.plusReady(function(){
					var userinfo = JSON.parse(localStorage.getItem('userinfo') || '{}');
					console.log(localStorage.getItem('userinfo'))
					
					var backlogin = doc.getElementById('backlogin');
					$.ajax('http://192.168.1.3:8888/sys/user',{
						data:{
						},
						dataType:'json',//服务器返回json格式数据
						crossDomain:true,
						cache:true,
						type:'GET',//HTTP请求类型
						timeout:10000,//超时时间设置为10秒；data
						
						  beforeSend: function(request) {
							  console.log(userinfo.refreshToken)
									   request.setRequestHeader("Content-Type",'application/json');
										request.setRequestHeader("authorization", userinfo.accessToken);
										request.setRequestHeader("refresh_token", userinfo.refreshToken);
									
						  
									  },
						success:function(data){
							console.log(JSON.stringify(data))
							if(data.code==0){
								vm.user=data.data
							}else{
								$.toast(data.msg)
							}
							
						},
						error:function(xhr,type,errorThrown){
							//异常处理；
							$.toast("系统异常")
						}
					});
				backlogin.addEventListener('tap',function(){
					$.ajax('http://192.168.1.3:8888/sys/user/logout',{
						data:{
						},
						dataType:'json',//服务器返回json格式数据
						crossDomain:true,
						cache:true,
						type:'GET',//HTTP请求类型
						timeout:10000,//超时时间设置为10秒；data
						
						  beforeSend: function(request) {
							  console.log(userinfo.refreshToken)
									   request.setRequestHeader("Content-Type",'application/json');
										request.setRequestHeader("authorization", userinfo.accessToken);
										request.setRequestHeader("refresh_token", userinfo.refreshToken);
									
						  
									  },
						success:function(data){
							console.log(JSON.stringify(data))
							if(data.code==0){
								$.toast("退出成功")
								localStorage.setItem("userinfo","")
								setTimeout(function () {
									mui.openWindow({url:'login.html'});
								},20);
							}else{
								$.toast(data.msg)
							}
							
						},
						error:function(xhr,type,errorThrown){
							//异常处理；
							$.toast("系统异常")
						}
					});

				 })
				})
				
				  // fs.addEventListener('tap',function(){
					 //  console.log("刷新")
					 //  var thisView = plus.webview.currentWebview().opener();
					 //   $.fire(thisView, 'refresh');
				  // })
			}(mui, document));
			
		</script>
	</body>

</html>
